
#include "tlv_pack_item.h"



#ifdef USE_TLV

#include "base_proto.h"
#include "tlv_pack_item.h"
#include "proto_pack.h"

//////////////////////////////////////////////////////////////////////////////

int user_info_pack(struct tlv_buf_t *buf, struct user_info_t *user_info)
{
	tlv_pack_int64(buf, user_info->id);
	tlv_pack_string(buf, user_info->name);
	tlv_pack_string(buf, user_info->nick);
	tlv_pack_int8(buf, user_info->sex);
	tlv_pack_int8(buf, user_info->age);
	tlv_pack_string(buf, user_info->birthday);
	tlv_pack_string(buf, user_info->passwd);
	tlv_pack_string(buf, user_info->email);
	tlv_pack_string(buf, user_info->note);

	return 0;
}

int user_info_unpack(struct tlv_buf_t *buf, struct user_info_t *user_info)
{
	tlv_unpack_int64(buf, &user_info->id);
	tlv_unpack_string(buf, user_info->name, sizeof(user_info->name)-1);
	tlv_unpack_string(buf, user_info->nick, sizeof(user_info->nick)-1);
	tlv_unpack_int8(buf, &user_info->sex);
	tlv_unpack_int8(buf, &user_info->age);
	tlv_unpack_string(buf, user_info->birthday, sizeof(user_info->birthday)-1);
	tlv_unpack_string(buf, user_info->passwd, sizeof(user_info->passwd)-1);
	tlv_unpack_string(buf, user_info->email, sizeof(user_info->email)-1);
	tlv_unpack_string(buf, user_info->note, sizeof(user_info->note)-1);

	return 0;
}

////////////////////////////////////////

int group_info_pack(struct tlv_buf_t *buf, struct group_info_t *group_info)
{
	tlv_pack_int64(buf, group_info->id);
	tlv_pack_string(buf, group_info->name);
	tlv_pack_int8(buf, group_info->type);
	tlv_pack_int64(buf, group_info->creater_id);
	tlv_pack_string(buf, group_info->note);

	return 0;
}

int group_info_unpack(struct tlv_buf_t *buf, struct group_info_t *group_info)
{
	tlv_unpack_int64(buf, &group_info->id);
	tlv_unpack_string(buf, group_info->name, sizeof(group_info->name)-1);
	tlv_unpack_int8(buf, &group_info->type);
	tlv_unpack_int64(buf, &group_info->creater_id);
	tlv_unpack_string(buf, group_info->note, sizeof(group_info->note)-1);

	return 0;
}

////////////////////////////////////////

int server_info_pack(struct tlv_buf_t *buf, struct server_info_t *server_info)
{
	tlv_pack_int16(buf, server_info->id);
	tlv_pack_string(buf, server_info->ip);
	tlv_pack_int16(buf, server_info->port);
	tlv_pack_int8(buf, server_info->type);
	tlv_pack_int8(buf, server_info->press);

	return 0;
}

int server_info_unpack(struct tlv_buf_t *buf, struct server_info_t *server_info)
{
	tlv_unpack_int16(buf, &server_info->id);
	tlv_unpack_string(buf, server_info->ip, sizeof(server_info->ip)-1);
	tlv_unpack_int16(buf, &server_info->port);
	tlv_unpack_int8(buf, &server_info->type);
	tlv_unpack_int8(buf, &server_info->press);

	return 0;
}

////////////////////////////////////////

int proto_head_pack(struct tlv_buf_t *buf, struct proto_head_t *proto_head)
{
    struct proto_head_t *head = (struct proto_head_t *)buf->data;

    head->magic = htons(proto_head->magic);
    head->ver = htons(proto_head->ver);
    head->flag = htons(proto_head->flag);
    head->type = htons(proto_head->type);
    head->len = htons(proto_head->len);

    buf->len = sizeof(struct proto_head_t);

	return 0;
}

int proto_head_unpack(struct tlv_buf_t *buf, struct proto_head_t *proto_head)
{
    struct proto_head_t *head = (struct proto_head_t *)buf->data;

    proto_head->magic = ntohs(head->magic);
    proto_head->ver = ntohs(head->ver);
    proto_head->flag = ntohs(head->flag);
    proto_head->type = ntohs(head->type);
    proto_head->len = ntohs(head->len);

    buf->pos += sizeof(struct proto_head_t);
    buf->len -= sizeof(struct proto_head_t);

	return 0;
}

int proto_head_insert(struct tlv_buf_t *buf, struct proto_head_t *proto_head)
{
    if(sizeof(buf->data) < buf->len+sizeof(struct proto_head_t)) {
        return -1;
    }

    memmove(buf->data, buf->data+sizeof(struct proto_head_t), buf->len);
    proto_head->len = buf->len;
    proto_head_pack(buf, proto_head);

    return 0;
}

int proto_pack(int type, void *ptr)
{


    return 0;
}


////////////////////////////////////////

int press_info_pack(struct tlv_buf_t *buf, struct press_info_t *press_info)
{
	tlv_pack_int16(buf, press_info->id);
	tlv_pack_int8(buf, press_info->type);
	tlv_pack_int8(buf, press_info->cpu);
	tlv_pack_int8(buf, press_info->mem);
	tlv_pack_int8(buf, press_info->bound);

	return 0;
}

int press_info_unpack(struct tlv_buf_t *buf, struct press_info_t *press_info)
{
	tlv_unpack_int16(buf, &press_info->id);
	tlv_unpack_int8(buf, &press_info->type);
	tlv_unpack_int8(buf, &press_info->cpu);
	tlv_unpack_int8(buf, &press_info->mem);
	tlv_unpack_int8(buf, &press_info->bound);

	return 0;
}

////////////////////////////////////////

int server_list_pack(struct tlv_buf_t *buf, struct server_list_t *server_list)
{
	tlv_pack_int16(buf, server_list->id);
	tlv_pack_int16(buf, server_list->count);
	for(int i=0; i<server_list->count; i++) {
		server_info_pack(buf, &server_list->server_list[i]);
	}

	return 0;
}

int server_list_unpack(struct tlv_buf_t *buf, struct server_list_t *server_list)
{
	tlv_unpack_int16(buf, &server_list->id);
	tlv_unpack_int8(buf, &server_list->count);
	for(int i=0; i<server_list->count; i++) {
		server_info_unpack(buf, &server_list->server_list[i]);
	}

	return 0;
}

//////////////////////////////////////////////////////////////////////////////

int user_register_req_pack(struct tlv_buf_t *buf, struct user_register_req_t *req)
{
	tlv_pack_int32(buf, req->session);
	user_info_pack(buf, &req->user_info);

	return 0;
}

int user_register_req_unpack(struct tlv_buf_t *buf, struct user_register_req_t *req)
{
	tlv_unpack_int32(buf, &req->session);
	user_info_unpack(buf, &req->user_info);

	return 0;
}

////////////////////////////////////////

int user_register_resp_pack(struct tlv_buf_t *buf, struct user_register_resp_t *resp)
{
	tlv_pack_int32(buf, resp->session);
	tlv_pack_int64(buf, resp->id);
	tlv_pack_int16(buf, resp->result);

	return 0;
}

int user_register_resp_unpack(struct tlv_buf_t *buf, struct user_register_resp_t *resp)
{
	tlv_unpack_int32(buf, &resp->session);
	tlv_unpack_int64(buf, &resp->id);
	tlv_unpack_int16(buf, &resp->result);

	return 0;
}

////////////////////////////////////////

int user_login_req_pack(struct tlv_buf_t *buf, struct user_login_req_t *req)
{
	tlv_pack_int64(buf, req->id);
	tlv_pack_string(buf, req->passwd);

	return 0;
}

int user_login_req_unpack(struct tlv_buf_t *buf, struct user_login_req_t *req)
{
	tlv_unpack_int64(buf, &req->id);
	tlv_unpack_string(buf, req->passwd, sizeof(req->passwd)-1);

	return 0;
}

////////////////////////////////////////

int user_login_resp_pack(struct tlv_buf_t *buf, struct user_login_resp_t *resp)
{
	tlv_pack_int64(buf, resp->id);
	user_info_pack(buf, &resp->user_info);
	tlv_pack_int16(buf, resp->result);

	return 0;
}

int user_login_resp_unpack(struct tlv_buf_t *buf, struct user_login_resp_t *resp)
{
	tlv_unpack_int64(buf, &resp->id);
	user_info_unpack(buf, &resp->user_info);
	tlv_unpack_int16(buf, &resp->result);

	return 0;
}

////////////////////////////////////////

int user_logout_req_pack(struct tlv_buf_t *buf, struct user_logout_req_t *req)
{
	tlv_pack_int64(buf, req->id);

	return 0;
}

int user_logout_req_unpack(struct tlv_buf_t *buf, struct user_logout_req_t *req)
{
	tlv_unpack_int64(buf, &req->id);

	return 0;
}

////////////////////////////////////////

int user_logout_resp_pack(struct tlv_buf_t *buf, struct user_logout_resp_t *resp)
{
	tlv_pack_int64(buf, resp->id);
	tlv_pack_int16(buf, resp->result);

	return 0;
}

int user_logout_resp_unpack(struct tlv_buf_t *buf, struct user_logout_resp_t *resp)
{
	tlv_unpack_int64(buf, &resp->id);
	tlv_unpack_int16(buf, &resp->result);

	return 0;
}

////////////////////////////////////////

int user_add_req_pack(struct tlv_buf_t *buf, struct user_add_req_t *req)
{
	tlv_pack_int64(buf, req->uid);
	tlv_pack_int64(buf, req->fid);
	tlv_pack_string(buf, req->note);

	return 0;
}

int user_add_req_unpack(struct tlv_buf_t *buf, struct user_add_req_t *req)
{
	tlv_unpack_int64(buf, &req->uid);
	tlv_unpack_int64(buf, &req->fid);
	tlv_unpack_string(buf, req->note, sizeof(req->note)-1);

	return 0;
}

////////////////////////////////////////

int user_add_resp_pack(struct tlv_buf_t *buf, struct user_add_resp_t *resp)
{
	tlv_pack_int64(buf, resp->uid);
	tlv_pack_int64(buf, resp->fid);
	tlv_pack_int16(buf, resp->result);

	return 0;
}

int user_add_resp_unpack(struct tlv_buf_t *buf, struct user_add_resp_t *resp)
{
	tlv_unpack_int64(buf, &resp->uid);
	tlv_unpack_int64(buf, &resp->fid);
	tlv_unpack_int16(buf, &resp->result);

	return 0;
}

////////////////////////////////////////

int user_kick_req_pack(struct tlv_buf_t *buf, struct user_kick_req_t *req)
{
	tlv_pack_int64(buf, req->uid);
	tlv_pack_int64(buf, req->kid);
	tlv_pack_string(buf, req->note);

	return 0;
}

int user_kick_req_unpack(struct tlv_buf_t *buf, struct user_kick_req_t *req)
{
	tlv_unpack_int64(buf, &req->uid);
	tlv_unpack_int64(buf, &req->kid);
	tlv_unpack_string(buf, req->note, sizeof(req->note)-1);

	return 0;
}

////////////////////////////////////////

int user_kick_resp_pack(struct tlv_buf_t *buf, struct user_kick_resp_t *resp)
{
	tlv_pack_int64(buf, resp->uid);
	tlv_pack_int64(buf, resp->kid);
	tlv_pack_int16(buf, resp->result);

	return 0;
}

int user_kick_resp_unpack(struct tlv_buf_t *buf, struct user_kick_resp_t *resp)
{
	tlv_unpack_int64(buf, &resp->uid);
	tlv_unpack_int64(buf, &resp->kid);
	tlv_unpack_int16(buf, &resp->result);

	return 0;
}

////////////////////////////////////////

int user_upgrade_req_pack(struct tlv_buf_t *buf, struct user_upgrade_req_t *req)
{
	tlv_pack_int64(buf, req->id);
	user_info_pack(buf, &req->user_info);

	return 0;
}

int user_upgrade_req_unpack(struct tlv_buf_t *buf, struct user_upgrade_req_t *req)
{
	tlv_unpack_int64(buf, &req->id);
	user_info_unpack(buf, &req->user_info);

	return 0;
}

////////////////////////////////////////

int user_upgrade_resp_pack(struct tlv_buf_t *buf, struct user_upgrade_resp_t *resp)
{
	tlv_pack_int64(buf, resp->id);
	tlv_pack_int16(buf, resp->result);

	return 0;
}

int user_upgrade_resp_unpack(struct tlv_buf_t *buf, struct user_upgrade_resp_t *resp)
{
	tlv_unpack_int64(buf, &resp->id);
	tlv_unpack_int16(buf, &resp->result);

	return 0;
}

////////////////////////////////////////

int user_info_req_pack(struct tlv_buf_t *buf, struct user_info_req_t *req)
{
	tlv_pack_int64(buf, req->id);

	return 0;
}

int user_info_req_unpack(struct tlv_buf_t *buf, struct user_info_req_t *req)
{
	tlv_unpack_int64(buf, &req->id);

	return 0;
}

////////////////////////////////////////

int user_info_resp_pack(struct tlv_buf_t *buf, struct user_info_resp_t *resp)
{
	tlv_pack_int64(buf, resp->id);
	user_info_pack(buf, &resp->user_info);
	tlv_pack_int16(buf, resp->result);

	return 0;
}

int user_info_resp_unpack(struct tlv_buf_t *buf, struct user_info_resp_t *resp)
{
	tlv_unpack_int64(buf, &resp->id);
	user_info_unpack(buf, &resp->user_info);
	tlv_unpack_int16(buf, &resp->result);

	return 0;
}

//////////////////////////////////////////////////////////////////////////////

int group_create_req_pack(struct tlv_buf_t *buf, struct group_create_req_t *req)
{
	tlv_pack_int64(buf, req->uid);
	group_info_pack(buf, &req->group_info);

	return 0;
}

int group_create_req_unpack(struct tlv_buf_t *buf, struct group_create_req_t *req)
{
	tlv_unpack_int64(buf, &req->uid);
	group_info_unpack(buf, &req->group_info);

	return 0;
}

////////////////////////////////////////

int group_create_resp_pack(struct tlv_buf_t *buf, struct group_create_resp_t *resp)
{
	tlv_pack_int64(buf, resp->uid);
	tlv_pack_int64(buf, resp->gid);
	tlv_pack_int16(buf, resp->result);

	return 0;
}

int group_create_resp_unpack(struct tlv_buf_t *buf, struct group_create_resp_t *resp)
{
	tlv_unpack_int64(buf, &resp->uid);
	tlv_unpack_int64(buf, &resp->gid);
	tlv_unpack_int16(buf, &resp->result);

	return 0;
}

////////////////////////////////////////

int group_delete_req_pack(struct tlv_buf_t *buf, struct group_delete_req_t *req)
{
	tlv_pack_int64(buf, req->uid);
	tlv_pack_int64(buf, req->gid);
	tlv_pack_string(buf, req->passwd);

	return 0;
}

int group_delete_req_unpack(struct tlv_buf_t *buf, struct group_delete_req_t *req)
{
	tlv_unpack_int64(buf, &req->uid);
	tlv_unpack_int64(buf, &req->gid);
	tlv_unpack_string(buf, req->passwd, sizeof(req->passwd)-1);

	return 0;
}

////////////////////////////////////////

int group_delete_resp_pack(struct tlv_buf_t *buf, struct group_delete_resp_t *resp)
{
	tlv_pack_int64(buf, resp->uid);
	tlv_pack_int64(buf, resp->gid);
	tlv_pack_int16(buf, resp->result);

	return 0;
}

int group_delete_resp_unpack(struct tlv_buf_t *buf, struct group_delete_resp_t *resp)
{
	tlv_unpack_int64(buf, &resp->uid);
	tlv_unpack_int64(buf, &resp->gid);
	tlv_unpack_int16(buf, &resp->result);

	return 0;
}

////////////////////////////////////////

int group_join_req_pack(struct tlv_buf_t *buf, struct group_join_req_t *req)
{
	tlv_pack_int64(buf, req->uid);
	tlv_pack_int64(buf, req->gid);
	tlv_pack_string(buf, req->note);

	return 0;
}

int group_join_req_unpack(struct tlv_buf_t *buf, struct group_join_req_t *req)
{
	tlv_unpack_int64(buf, &req->uid);
	tlv_unpack_int64(buf, &req->gid);
	tlv_unpack_string(buf, req->note, sizeof(req->note)-1);

	return 0;
}

////////////////////////////////////////

int group_join_resp_pack(struct tlv_buf_t *buf, struct group_join_resp_t *resp)
{
	tlv_pack_int64(buf, resp->uid);
	tlv_pack_int64(buf, resp->gid);
	tlv_pack_int16(buf, resp->result);

	return 0;
}

int group_join_resp_unpack(struct tlv_buf_t *buf, struct group_join_resp_t *resp)
{
	tlv_unpack_int64(buf, &resp->uid);
	tlv_unpack_int64(buf, &resp->gid);
	tlv_unpack_int16(buf, &resp->result);

	return 0;
}

////////////////////////////////////////

int group_quit_req_pack(struct tlv_buf_t *buf, struct group_quit_req_t *req)
{
	tlv_pack_int64(buf, req->uid);
	tlv_pack_int64(buf, req->gid);
	tlv_pack_string(buf, req->note);

	return 0;
}

int group_quit_req_unpack(struct tlv_buf_t *buf, struct group_quit_req_t *req)
{
	tlv_unpack_int64(buf, &req->uid);
	tlv_unpack_int64(buf, &req->gid);
	tlv_unpack_string(buf, req->note, sizeof(req->note)-1);

	return 0;
}

////////////////////////////////////////

int group_quit_resp_pack(struct tlv_buf_t *buf, struct group_quit_resp_t *resp)
{
	tlv_pack_int64(buf, resp->uid);
	tlv_pack_int64(buf, resp->gid);
	tlv_pack_int16(buf, resp->result);

	return 0;
}

int group_quit_resp_unpack(struct tlv_buf_t *buf, struct group_quit_resp_t *resp)
{
	tlv_unpack_int64(buf, &resp->uid);
	tlv_unpack_int64(buf, &resp->gid);
	tlv_unpack_int16(buf, &resp->result);

	return 0;
}

////////////////////////////////////////

int group_upgrade_req_pack(struct tlv_buf_t *buf, struct group_upgrade_req_t *req)
{
	tlv_pack_int64(buf, req->uid);
	group_info_pack(buf, &req->group_info);

	return 0;
}

int group_upgrade_req_unpack(struct tlv_buf_t *buf, struct group_upgrade_req_t *req)
{
	tlv_unpack_int64(buf, &req->uid);
	group_info_unpack(buf, &req->group_info);

	return 0;
}

////////////////////////////////////////

int group_upgrade_resp_pack(struct tlv_buf_t *buf, struct group_upgrade_resp_t *resp)
{
	tlv_pack_int64(buf, resp->uid);
	tlv_pack_int64(buf, resp->gid);
	tlv_pack_int16(buf, resp->result);

	return 0;
}

int group_upgrade_resp_unpack(struct tlv_buf_t *buf, struct group_upgrade_resp_t *resp)
{
	tlv_unpack_int64(buf, &resp->uid);
	tlv_unpack_int64(buf, &resp->gid);
	tlv_unpack_int16(buf, &resp->result);

	return 0;
}

//////////////////////////////////////////////////////////////////////////////

int group_info_req_pack(struct tlv_buf_t *buf, struct group_info_req_t *req)
{
	tlv_pack_int64(buf, req->uid);
	tlv_pack_int64(buf, req->gid);

	return 0;
}

int group_info_req_unpack(struct tlv_buf_t *buf, struct group_info_req_t *req)
{
	tlv_unpack_int64(buf, &req->uid);
	tlv_unpack_int64(buf, &req->gid);

	return 0;
}

////////////////////////////////////////

int group_info_resp_pack(struct tlv_buf_t *buf, struct group_info_resp_t *resp)
{
	tlv_pack_int64(buf, resp->uid);
	group_info_pack(buf, &resp->group_info);
	tlv_pack_int16(buf, resp->result);

	return 0;
}

int group_info_resp_unpack(struct tlv_buf_t *buf, struct group_info_resp_t *resp)
{
	tlv_unpack_int64(buf, &resp->uid);
	group_info_unpack(buf, &resp->group_info);
	tlv_unpack_int16(buf, &resp->result);

	return 0;
}

//////////////////////////////////////////////////////////////////////////////

int msg_send_user_pack(struct tlv_buf_t *buf, struct msg_send_user_t *send_user)
{
	tlv_pack_int64(buf, send_user->fid);
	tlv_pack_string(buf, send_user->fnick);
	tlv_pack_int64(buf, send_user->tid);
	tlv_pack_string(buf, send_user->msg);

	return 0;
}

int msg_send_user_unpack(struct tlv_buf_t *buf, struct msg_send_user_t *send_user)
{
	tlv_unpack_int64(buf, &send_user->fid);
	tlv_unpack_string(buf,  send_user->fnick, sizeof(send_user->fnick)-1);
	tlv_unpack_int64(buf, &send_user->tid);
	tlv_unpack_string(buf, send_user->msg, sizeof(send_user->msg)-1);

	return 0;
}

////////////////////////////////////////

int msg_receive_user_pack(struct tlv_buf_t *buf, struct msg_receive_user_t *receive_user)
{
	tlv_pack_int64(buf, receive_user->fid);
	tlv_pack_string(buf,  receive_user->fnick);
	tlv_pack_int64(buf, receive_user->tid);
	tlv_pack_string(buf, receive_user->sndtime);
	tlv_pack_string(buf, receive_user->msg);

	return 0;
}

int msg_receive_user_unpack(struct tlv_buf_t *buf, struct msg_receive_user_t *receive_user)
{
	tlv_unpack_int64(buf, &receive_user->fid);
	tlv_unpack_string(buf,  receive_user->fnick, sizeof(receive_user->fnick)-1);
	tlv_unpack_int64(buf, &receive_user->tid);
	tlv_unpack_string(buf, receive_user->sndtime, sizeof(receive_user->sndtime)-1);
	tlv_unpack_string(buf, receive_user->msg, sizeof(receive_user->msg)-1);

	return 0;
}

////////////////////////////////////////

int msg_send_group_pack(struct tlv_buf_t *buf, struct msg_send_group_t *send_group)
{
	tlv_pack_int64(buf, send_group->uid);
	tlv_pack_int64(buf, send_group->gid);
	tlv_pack_string(buf, send_group->msg);

	return 0;
}

int msg_send_group_unpack(struct tlv_buf_t *buf, struct msg_send_group_t *send_group)
{
	tlv_unpack_int64(buf, &send_group->uid);
	tlv_unpack_int64(buf, &send_group->gid);
	tlv_unpack_string(buf, send_group->msg, sizeof(send_group->msg)-1);

	return 0;
}

////////////////////////////////////////

int msg_receive_group_pack(struct tlv_buf_t *buf, struct msg_receive_group_t *receive_group)
{
	tlv_pack_int64(buf, receive_group->uid);
	tlv_pack_int64(buf, receive_group->gid);
	tlv_pack_string(buf, receive_group->sndtime);
	tlv_pack_string(buf, receive_group->msg);

	return 0;
}

int msg_receive_group_unpack(struct tlv_buf_t *buf, struct msg_receive_group_t *receive_group)
{
	tlv_unpack_int64(buf, &receive_group->uid);
	tlv_unpack_int64(buf, &receive_group->gid);
	tlv_unpack_string(buf, receive_group->sndtime, sizeof(receive_group->sndtime)-1);
	tlv_unpack_string(buf, receive_group->msg, sizeof(receive_group->msg)-1);

	return 0;
}

////////////////////////////////////////

int user_friends_req_pack(struct tlv_buf_t *buf, struct user_friends_req_t *req)
{
	tlv_pack_int64(buf, req->uid);

	return 0;
}

int user_friends_req_unpack(struct tlv_buf_t *buf, struct user_friends_req_t *req)
{
	tlv_unpack_int64(buf, &req->uid);

	return 0;
}

////////////////////////////////////////

int user_friends_resp_pack(struct tlv_buf_t *buf, struct user_friends_resp_t *resp)
{
	tlv_pack_int64(buf, resp->uid);
	tlv_pack_int8(buf, resp->count);
	for(int i=0; i<resp->count; i++) {
		user_info_pack(buf, &resp->list[i]);
	}
	tlv_pack_int16(buf, resp->result);

	return 0;
}

int user_friends_resp_unpack(struct tlv_buf_t *buf, struct user_friends_resp_t *resp)
{
	tlv_unpack_int64(buf, &resp->uid);
	tlv_unpack_int8(buf, &resp->count);
	for(int i=0; i<resp->count; i++) {
		user_info_unpack(buf, &resp->list[i]);
	}
	tlv_unpack_int16(buf, &resp->result);

	return 0;
}

////////////////////////////////////////

int user_groups_req_pack(struct tlv_buf_t *buf, struct user_groups_req_t *req)
{
	tlv_pack_int64(buf, req->uid);

	return 0;
}

int user_groups_req_unpack(struct tlv_buf_t *buf, struct user_groups_req_t *req)
{
	tlv_unpack_int64(buf, &req->uid);

	return 0;
}

////////////////////////////////////////

int user_groups_resp_pack(struct tlv_buf_t *buf, struct user_groups_resp_t *resp)
{
	tlv_pack_int64(buf, resp->uid);
	tlv_pack_int8(buf, resp->count);
	for(int i=0; i<resp->count; i++) {
		group_info_pack(buf, &resp->list[i]);
	}
	tlv_pack_int16(buf, resp->result);

	return 0;
}

int user_groups_resp_unpack(struct tlv_buf_t *buf, struct user_groups_resp_t *resp)
{
	tlv_unpack_int64(buf, &resp->uid);
	tlv_unpack_int8(buf, &resp->count);
	for(int i=0; i<resp->count; i++) {
		group_info_unpack(buf, &resp->list[i]);
	}
	tlv_unpack_int16(buf, &resp->result);

	return 0;
}

////////////////////////////////////////

int group_users_req_pack(struct tlv_buf_t *buf, struct group_users_req_t *req)
{
	tlv_pack_int64(buf, req->uid);
	tlv_pack_int64(buf, req->gid);

	return 0;
}

int group_users_req_unpack(struct tlv_buf_t *buf, struct group_users_req_t *req)
{
	tlv_unpack_int64(buf, &req->uid);
	tlv_unpack_int64(buf, &req->gid);

	return 0;
}

////////////////////////////////////////

int group_users_resp_pack(struct tlv_buf_t *buf, struct group_users_resp_t *resp)
{
	tlv_pack_int64(buf, resp->uid);
	tlv_pack_int64(buf, resp->gid);
	tlv_pack_int8(buf, resp->count);
	for(int i=0; i<resp->count; i++) {
		user_info_pack(buf, &resp->list[i]);
	}
	tlv_pack_int16(buf, resp->result);

	return 0;
}

int group_users_resp_unpack(struct tlv_buf_t *buf, struct group_users_resp_t *resp)
{
	tlv_unpack_int64(buf, &resp->uid);
	tlv_unpack_int64(buf, &resp->gid);
	tlv_unpack_int8(buf, &resp->count);
	for(int i=0; i<resp->count; i++) {
		user_info_unpack(buf, &resp->list[i]);
	}
	tlv_unpack_int16(buf, &resp->result);

	return 0;
}

//////////////////////////////////////////////////////////////////////////////

int server_reg_req_pack(struct tlv_buf_t *buf, struct server_reg_req_t *req)
{
	tlv_pack_int16(buf, req->id);
	tlv_pack_string(buf,  req->ip);
	tlv_pack_int16(buf, req->port);
	tlv_pack_int8(buf, req->type);

	return 0;
}

int server_reg_req_unpack(struct tlv_buf_t *buf, struct server_reg_req_t *req)
{
	tlv_unpack_int16(buf, &req->id);
	tlv_unpack_string(buf,  req->ip, sizeof(req->ip)-1);
	tlv_unpack_int16(buf, &req->port);
	tlv_unpack_int8(buf, &req->type);

	return 0;
}

////////////////////////////////////////

int server_reg_resp_pack(struct tlv_buf_t *buf, struct server_reg_resp_t *resp)
{
	tlv_pack_int16(buf, resp->id);
	tlv_pack_int16(buf, resp->result);

	return 0;
}

int server_reg_resp_unpack(struct tlv_buf_t *buf, struct server_reg_resp_t *resp)
{
	tlv_unpack_int16(buf, &resp->id);
	tlv_unpack_int16(buf, &resp->result);

	return 0;
}

////////////////////////////////////////

int agent_get_req_pack(struct tlv_buf_t *buf, struct agent_get_req_t *req)
{
	return 0;
}

int agent_get_req_unpack(struct tlv_buf_t *buf, struct agent_get_req_t *req)
{
	return 0;
}

////////////////////////////////////////

int agent_get_resp_pack(struct tlv_buf_t *buf, struct agent_get_resp_t *resp)
{
	tlv_pack_int16(buf, resp->id);
	tlv_pack_string(buf,  resp->ip);
	tlv_pack_int16(buf, resp->port);
	tlv_pack_int16(buf, resp->result);

	return 0;
}

int agent_get_resp_unpack(struct tlv_buf_t *buf, struct agent_get_resp_t *resp)
{
	tlv_unpack_int16(buf, &resp->id);
	tlv_unpack_string(buf,  resp->ip, sizeof(resp->ip)-1);
	tlv_unpack_int16(buf, &resp->port);
	tlv_unpack_int16(buf, &resp->result);

	return 0;
}

////////////////////////////////////////

int dispatch_press_pack(struct tlv_buf_t *buf, struct dispatch_press_t *dispatch_press)
{
	tlv_pack_int16(buf, dispatch_press->id);
	tlv_pack_int8(buf, dispatch_press->press);

	return 0;
}

int dispatch_press_unpack(struct tlv_buf_t *buf, struct dispatch_press_t *dispatch_press)
{
	tlv_unpack_int16(buf, &dispatch_press->id);
	tlv_unpack_int8(buf, &dispatch_press->press);

	return 0;
}

//////////////////////////////////////////////////////////////////////////////


#endif // USE_TLV
